package com.zhuiYun.project.api.alipay.controller;

import com.alipay.api.AlipayApiException;
import com.zhuiYun.project.api.alipay.entity.AlipayEntity;
import com.zhuiYun.project.api.alipay.service.AlipayService;
import com.zhuiYun.project.common.response.CommonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * lzy 2022-8-15 19点40分
 */
@RequestMapping("Alipay")
@CrossOrigin
@RestController
public class AlipayController {

    @Autowired
    AlipayService alipayService;

    @PostMapping("/notify")
    public String queryNotify(String notify_time,String trade_no, String buyer_id, String total_amount){
        System.out.println(notify_time + "," + trade_no + "," + buyer_id + "," + total_amount);
        if (buyer_id != null) {
            return "Success";
        } else {
            return "false";
        }
    }

    @GetMapping("/return")
    public void queryReturn(){
        System.out.println("测试同步请求");
    }

    /**
    * @Description 连接支付宝当面付接口，传入价格、商品编号返回支付二维码
    * @Author lzy
    * @Date 2023/4/12 13:46
    * @Return com.zhuiYun.project.common.response.CommonResult
    * @param alipayEntity
    */
    @PostMapping("qrcode")
    public CommonResult qecode(@RequestBody AlipayEntity alipayEntity) throws AlipayApiException {
        Map<String, Object> qecode = alipayService.qecode(alipayEntity);
        return CommonResult.ok(qecode);
    }

    /**
     * 询问订单状态
     * lzy 2022-8-16 09点46分6
     * @param code
     * @return
     * @throws AlipayApiException
     */
    @GetMapping("query")
    public CommonResult query(String code) throws AlipayApiException {
        Map<String, Object> query = alipayService.query(code);
        return CommonResult.ok(query);
    }

}
